VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form FrmLop 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Lop"
   ClientHeight    =   8085
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   12150
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8085
   ScaleWidth      =   12150
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame 
      Caption         =   "Thong tin chi tiet"
      Height          =   3495
      Left            =   4200
      TabIndex        =   0
      Top             =   360
      Width           =   7815
      Begin VB.TextBox txtKhoa 
         Height          =   375
         Left            =   1560
         TabIndex        =   15
         Top             =   2040
         Width           =   2055
      End
      Begin VB.CommandButton btnChonKhoaNgoai 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   14
         Top             =   1560
         Width           =   375
      End
      Begin VB.TextBox txtMaLop 
         Height          =   375
         Left            =   1560
         TabIndex        =   12
         Top             =   600
         Width           =   2055
      End
      Begin VB.TextBox txtTenNganh 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   7
         Top             =   1560
         Width           =   4095
      End
      Begin VB.TextBox txtTenLop 
         Height          =   375
         Left            =   1560
         TabIndex        =   6
         Top             =   1080
         Width           =   4575
      End
      Begin VB.CommandButton btnNhapMoi 
         Caption         =   "Nhap moi"
         Height          =   375
         Left            =   2280
         TabIndex        =   5
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton btnThem 
         Caption         =   "Them"
         Height          =   375
         Left            =   3600
         TabIndex        =   4
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton btnXoa 
         Caption         =   "Xoa"
         Height          =   375
         Left            =   4920
         TabIndex        =   3
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton btnCapNhap 
         Caption         =   "Cap nhat"
         Height          =   375
         Left            =   6240
         TabIndex        =   2
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton btnChon 
         Caption         =   "Chon"
         Height          =   375
         Left            =   120
         TabIndex        =   1
         Top             =   2760
         Width           =   1215
      End
      Begin VB.Label Label3 
         Caption         =   "Khoa"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   2160
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "Ma lop"
         Height          =   255
         Left            =   360
         TabIndex        =   13
         Top             =   720
         Width           =   975
      End
      Begin VB.Label lblStation 
         Caption         =   "Nganh"
         Height          =   255
         Left            =   360
         TabIndex        =   9
         Top             =   1680
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "Ten lop"
         Height          =   255
         Left            =   360
         TabIndex        =   8
         Top             =   1200
         Width           =   975
      End
   End
   Begin MSComctlLib.ListView lstvData 
      Height          =   7455
      Left            =   120
      TabIndex        =   10
      Top             =   480
      Width           =   3975
      _ExtentX        =   7011
      _ExtentY        =   13150
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.Label Label 
      Caption         =   "Danh muc lop"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   11
      Top             =   120
      Width           =   4095
   End
End
Attribute VB_Name = "FrmLop"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents formNganh As FrmNganh
Attribute formNganh.VB_VarHelpID = -1
Private m_sMaNganh As String
Private m_objLop As clsLop
Private m_ObjADORst  As ADODB.Recordset
Event EVENTChooseItem(ByVal MaLop As String, ByVal TenLop As String)
Public EnableBtnChon As Boolean

Private Sub btnCapNhap_Click()
    Dim objLopDto As clsLop
    
    Set m_objLop = New clsLop
    Set objLopDto = New clsLop
    
    objLopDto.MaLop = Trim(txtMaLop.Text)
    objLopDto.MaNganh = Trim(m_sMaNganh)
    objLopDto.TenLop = Trim(txtTenLop.Text)
    objLopDto.Khoa = Trim(txtKhoa.Text)
    
    If m_objLop.Update(objLopDto) Then
        LoadData
        MsgBox GetReport("CapNhat", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("CapNhat", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub btnChon_Click()
    If Not IsAnySelectedItem(lstvData) Then Exit Sub
    RaiseEvent EVENTChooseItem(txtMaLop.Text, txtTenLop.Text)
    Unload Me
End Sub

Private Sub btnChonKhoaNgoai_Click()
    Set formNganh = New FrmNganh
    formNganh.EnableBtnChon = True
    formNganh.Show 1, Me
End Sub

Private Sub ResetFields()
    m_sMaNganh = ""
    txtTenNganh.Text = ""
    txtMaLop.Text = ""
    txtTenLop.Text = ""
    txtKhoa.Text = ""
End Sub

Private Sub btnNhapMoi_Click()
    ResetFields
    txtMaLop.Locked = False
End Sub

Private Sub btnThem_Click()
    Dim objLopDto As clsLop
    Dim errText As String
    
    If Not ValidateInput(errText) Then
        MsgBox errText, vbCritical, "ThongBao"
        Exit Sub
    End If
    
    Set m_objLop = New clsLop
    Set objLopDto = New clsLop
    
    objLopDto.MaLop = Trim(txtMaLop.Text)
    objLopDto.MaNganh = Trim(m_sMaNganh)
    objLopDto.TenLop = Trim(txtTenLop.Text)
    objLopDto.Khoa = Trim(txtKhoa.Text)
    
    If m_objLop.Insert(objLopDto) Then
        LoadData
        ResetFields
        MsgBox GetReport("Them", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("Them", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub LoadData()
    Dim i As Integer
    Dim vLstViewItem As ListItem
    
    Set m_objLop = New clsLop
    Set m_ObjADORst = m_objLop.SelectAll
    lstvData.ListItems.Clear
    i = 1
    
    Do While Not m_ObjADORst.EOF
        Set vLstViewItem = lstvData.ListItems.Add(i)
        vLstViewItem = m_ObjADORst!MaLop
        vLstViewItem.SubItems(1) = m_ObjADORst!TenLop
        vLstViewItem.SubItems(2) = m_ObjADORst!tennganh
        m_ObjADORst.MoveNext
        i = i + 1
    Loop

End Sub

Private Sub btnXoa_Click()
    If Trim(txtMaLop.Text) = "" Then Exit Sub
    
    Set m_objLop = New clsLop
     
    If MsgBox(GetReport("Xoa", "XacNhan"), vbInformation + vbOKCancel, "ThongBao") = vbOK Then
        If m_objLop.Delete(Trim(txtMaLop.Text)) Then
            LoadData
            ResetFields
            MsgBox GetReport("Xoa", "ThanhCong"), vbInformation, "ThongBao"
        Else
            MsgBox GetReport("Xoa", "ThatBai"), vbCritical, "ThongBao"
        End If
    End If
End Sub

Private Sub Form_Load()
    Init
    LoadData
    Call ClearSelection(lstvData)
End Sub

Public Sub Init()
    lstvData.ColumnHeaders.Clear
    lstvData.ColumnHeaders.Add , , "Ma Lop", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Ten Lop", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Ten Nganh", lstvData.Width / 3
    
    If EnableBtnChon Then
        btnChon.Enabled = True
    Else
        btnChon.Enabled = False
    End If
End Sub

Private Sub formNganh_EVENTChooseItem(ByVal MaNganh As String, ByVal tennganh As String)
    m_sMaNganh = MaNganh
    txtTenNganh.Text = tennganh
End Sub

Public Function ValidateInput(ByRef errText As String) As Boolean
    ValidateInput = True
    If Trim(txtTenNganh.Text) = "" Then
        errText = "Ban chua chon nganh"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtMaLop.Text) = "" Then
        errText = "Ban chua nhap ma lop"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenLop.Text) = "" Then
        errText = "Ban chua nhap ten lop"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtKhoa.Text) = "" Then
        errText = "Ban chua nhap khoa"
        ValidateInput = False
        Exit Function
    End If
End Function

Private Sub lstvData_ItemClick(ByVal item As MSComctlLib.ListItem)
    Set m_ObjADORst = m_objLop.SelectByID(item)
    If Not m_ObjADORst Is Nothing Then
        m_sMaNganh = m_ObjADORst!MaNganh
        txtTenNganh.Text = m_ObjADORst!tennganh
        txtMaLop.Text = m_ObjADORst!MaLop
        txtTenLop.Text = m_ObjADORst!TenLop
        txtKhoa.Text = m_ObjADORst!Khoa
        
        txtMaLop.Locked = True
    End If
End Sub

